package com.luisliuyi.demo.hook.ams;

import java.lang.reflect.Field;

public abstract class AmsHooker {

    // 即IActivityManagerSingleton实例
    protected abstract Object getHookObj();

    // 即mInstance
    protected abstract Field getHookField();

    // 即am
    abstract Object getTarget();

    // 接口，用来创建Proxy
    abstract Object getInterfaces();

    // 通过反射，将am替换成proxy
    public void hookAms(Object proxy) {
        try {
            Object hookObj = getHookObj();
            Field hookField = getHookField();
            if (hookObj != null && hookField != null && proxy != null) {
                hookField.set(hookObj, proxy);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

